import { createRouter, createWebHistory } from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'
import type { Component } from 'vue'
import Login from '@/views/login/index.vue'
import Layout from '@/layout/index.vue'
import ErrorPage from '@/views/error/index.vue'

// 静态路由（比如登录页、404等，不需要权限的页面）
const staticRoutes: RouteRecordRaw[] = [
  {
    path: '/',
    name: 'Login',
    meta: { title: '登录', keepAlive: true },
    component: Login
  },
  {
    path: '/',
    component: Layout,
    children: [
      {
        path: '/home',
        name: 'Home',
        meta: { title: '首页', keepAlive: true },
        component: ()=>import('@/views/home/index.vue'),
      },
      {
        path: '/sys/user',
        name: 'User',
        meta: { title: '用户管理', keepAlive: true },
        component: ()=>import('@/views/sys/user/index.vue'),
      },
      {
        path: '/sys/org',
        name: 'Org',
        meta: { title: '部门管理', keepAlive: true },
        component: ()=>import('@/views/sys/org/index.vue'),
      },
      {
        path: '/sys/role',
        name: "Role",
        meta: { title: '角色管理', keepAlive: true },
        component: ()=>import('@/views/sys/role/index.vue'),
      },
      {
        path: '/ams/client',
        name: 'Client',
        meta: { title: '客户端管理', keepAlive: true },
        component: ()=>import('@/views/ams/client/index.vue'),
      },
      {
        path: '/ams/policy',
        name: 'policy',
        meta: { title: '策略管理', keepAlive: true },
        component: () => import('@/views/ams/policy/index.vue'),
      },
      {
        path: '/ams/plugin',
        name: 'plugin',
        meta: { title: '插件管理', keepAlive: true },
        component: () => import('@/views/ams/plugin/index.vue'),
      },
      {
        path: '/ams/asset',
        name: 'asset',
        meta: { title: '资产管理', keepAlive: true },
        component: () => import('@/views/ams/asset/index.vue'),
      },
      {
        path: '/ams/assetConsumables',
        name: 'assetConsumables',
        meta: { title: '资产分发', keepAlive: true },
        component: () => import('@/views/ams/consumables/index.vue'),
      },
      {
        path: '/ams/assetType',
        name: 'assetType',
        meta: { title: '资产类型', keepAlive: true },
        component: () => import('@/views/ams/assetType/index.vue'),
      },
      {
        path: '/ams/assetCategory',
        name: 'assetCategory',
        meta: { title: 'assetCategory', keepAlive: true },
        component: () => import('@/views/ams/assetCategory/index.vue'),
      },
      {
        path: '/cap/my',
        name: 'capMy',
        meta: { title: 'capMy', keepAlive: true },
        component: () => import('@/views/cap/my/index.vue'),
      },
      {
        path: '/cap/host',
        name: 'capHost',
        component: () => import('@/views/cap/host/index.vue'),
      },
      {
        path: '/cap/cluster',
        name: 'capCluster',
        meta: { title: 'capCluster', keepAlive: true },
        component: () => import('@/views/cap/cluster/index.vue'),
      },
      {
        path: '/cap/session',
        name: 'capSession',
        meta: { title: 'capSession', keepAlive: true },
        component: () => import('@/views/cap/session/index.vue'),
      },
      {
        path: '/cap/certify',
        name: 'capCertify',
        meta: { title: 'capCertify', keepAlive: true },
        component: () => import('@/views/cap/certify/index.vue'),
      },
      {
        path: '/cap/app',
        name: 'capApp',
        meta: { title: 'capApp', keepAlive: true },
        component: () => import('@/views/cap/app/index.vue'),
      },
      { path: '/:pathMatch(.*)', component: ErrorPage },
    ]
  }
]

// 默认路由
export const router =  createRouter({
  history: createWebHistory(),
  routes: staticRoutes
})

export default router
